/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.uniandes.contextMobileApp.midlet;

import co.edu.uniandes.contextMobileApp.mundo.ContextMobileApp;
import java.util.Vector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import org.netbeans.microedition.lcdui.SimpleTableModel;
import org.netbeans.microedition.lcdui.TableItem;
import org.netbeans.microedition.lcdui.TableModel;
import org.netbeans.microedition.lcdui.pda.FileBrowser;

/**
 * @author Luis Javier Bautista
 */
public class HelloMIDlet extends MIDlet implements CommandListener {
    
    private boolean midletPaused = false; 
    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private java.util.Hashtable __previousDisplayables = new java.util.Hashtable();
    private Command exitCommand;
    private Command cmdBuscarArchivo;
    private Command cmdBusqueda;
    private Command cmdBackBusqueda;
    private Command cmdBackAgregar;
    private Command cmdAgregar;
    private Command cmdCancelBrowser;
    private Command cmdAgregarArchivo;
    private Form formPrincipal;
    private ImageItem imageItem;
    private Form formBusqueda;
    private TableItem tableItem;
    private Form formAgregar;
    private StringItem lbNombreArchivo;
    private StringItem lbTamanio;
    private FileBrowser fileBrowser;
    private Alert alertArchivoAgregado;
    private SimpleTableModel simpleTableModel;
    private Font font1;
    private Image image;
    //</editor-fold>//GEN-END:|fields|0|

    private FileConnection selectedFile;
    
    private ContextMobileApp mundo;
    
    /**
     * The HelloMIDlet constructor.
     */
    public HelloMIDlet() {
        //mundo = new ContextMobileApp(this);
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    /**
     * Switches a display to previous displayable of the current displayable.
     * The <code>display</code> instance is obtain from the <code>getDisplay</code> method.
     */
    private void switchToPreviousDisplayable() {
        Displayable __currentDisplayable = getDisplay().getCurrent();
        if (__currentDisplayable != null) {
            Displayable __nextDisplayable = (Displayable) __previousDisplayables.get(__currentDisplayable);
            if (__nextDisplayable != null) {
                switchDisplayable(null, __nextDisplayable);
            }
        }
    }
    //</editor-fold>//GEN-END:|methods|0|
    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initializes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getFormPrincipal());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        Displayable __currentDisplayable = display.getCurrent();
        if (__currentDisplayable != null  &&  nextDisplayable != null) {
            __previousDisplayables.put(nextDisplayable, __currentDisplayable);
        }
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == fileBrowser) {//GEN-BEGIN:|7-commandAction|1|44-preAction
            if (command == FileBrowser.SELECT_FILE_COMMAND) {//GEN-END:|7-commandAction|1|44-preAction
                // write pre-action user code here
                try{
                    
                    selectedFile = fileBrowser.getSelectedFile();
                    lbNombreArchivo.setText(selectedFile.getName());
                    lbTamanio.setText((selectedFile.fileSize()/1000)+" KBytes");
                }catch(Exception e){
                    e.printStackTrace();
                }
                switchDisplayable(null, getFormAgregar());//GEN-LINE:|7-commandAction|2|44-postAction
                // write post-action user code here
            } else if (command == cmdCancelBrowser) {//GEN-LINE:|7-commandAction|3|48-preAction
                // write pre-action user code here
                switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|4|48-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|5|59-preAction
        } else if (displayable == formAgregar) {
            if (command == cmdAgregarArchivo) {//GEN-END:|7-commandAction|5|59-preAction
                // write pre-action user code here
                mundo.agregarArchivo(selectedFile);
                switchDisplayable(null, getAlertArchivoAgregado());//GEN-LINE:|7-commandAction|6|59-postAction
                // write post-action user code here
            } else if (command == cmdBackAgregar) {//GEN-LINE:|7-commandAction|7|40-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormPrincipal());//GEN-LINE:|7-commandAction|8|40-postAction
                // write post-action user code here
            } else if (command == cmdBuscarArchivo) {//GEN-LINE:|7-commandAction|9|45-preAction
                // write pre-action user code here
                switchDisplayable(null, getFileBrowser());//GEN-LINE:|7-commandAction|10|45-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|11|33-preAction
        } else if (displayable == formBusqueda) {
            if (command == cmdBackBusqueda) {//GEN-END:|7-commandAction|11|33-preAction
                // write pre-action user code here
                switchToPreviousDisplayable();//GEN-LINE:|7-commandAction|12|33-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|13|37-preAction
        } else if (displayable == formPrincipal) {
            if (command == cmdAgregar) {//GEN-END:|7-commandAction|13|37-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormAgregar());//GEN-LINE:|7-commandAction|14|37-postAction
                // write post-action user code here
            } else if (command == cmdBusqueda) {//GEN-LINE:|7-commandAction|15|27-preAction
                // write pre-action user code here
                Vector v = mundo.getArchivos();
                Vector v2 = new Vector();
                for (int i = 0; i < v.size(); i++) {
                    v2.addElement(((FileConnection)v.elementAt(i)).getName());
                }
                mundo.setResultadosBusqueda(v2);
                switchDisplayable(null, getFormBusqueda());//GEN-LINE:|7-commandAction|16|27-postAction
                // write post-action user code here
            } else if (command == exitCommand) {//GEN-LINE:|7-commandAction|17|19-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|18|19-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|19|7-postCommandAction
        }//GEN-END:|7-commandAction|19|7-postCommandAction
        // write post-action user code here
    }//GEN-BEGIN:|7-commandAction|20|
    //</editor-fold>//GEN-END:|7-commandAction|20|


    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|18-getter|0|18-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|18-getter|0|18-preInit
            // write pre-init user code here
            exitCommand = new Command("Exit", Command.EXIT, 0);//GEN-LINE:|18-getter|1|18-postInit
            // write post-init user code here
        }//GEN-BEGIN:|18-getter|2|
        return exitCommand;
    }
    //</editor-fold>//GEN-END:|18-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formPrincipal ">//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initiliazed instance of formPrincipal component.
     * @return the initialized component instance
     */
    public Form getFormPrincipal() {
        if (formPrincipal == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
            formPrincipal = new Form("TuxtaMovil", new Item[] { getImageItem() });//GEN-BEGIN:|14-getter|1|14-postInit
            formPrincipal.addCommand(getExitCommand());
            formPrincipal.addCommand(getCmdBusqueda());
            formPrincipal.addCommand(getCmdAgregar());
            formPrincipal.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
            // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return formPrincipal;
    }
    //</editor-fold>//GEN-END:|14-getter|2|



    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cmdBuscarArchivo ">//GEN-BEGIN:|24-getter|0|24-preInit
    /**
     * Returns an initiliazed instance of cmdBuscarArchivo component.
     * @return the initialized component instance
     */
    public Command getCmdBuscarArchivo() {
        if (cmdBuscarArchivo == null) {//GEN-END:|24-getter|0|24-preInit
            // write pre-init user code here
            cmdBuscarArchivo = new Command("Buscar", Command.SCREEN, 0);//GEN-LINE:|24-getter|1|24-postInit
            // write post-init user code here
        }//GEN-BEGIN:|24-getter|2|
        return cmdBuscarArchivo;
    }
    //</editor-fold>//GEN-END:|24-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cmdBusqueda ">//GEN-BEGIN:|26-getter|0|26-preInit
    /**
     * Returns an initiliazed instance of cmdBusqueda component.
     * @return the initialized component instance
     */
    public Command getCmdBusqueda() {
        if (cmdBusqueda == null) {//GEN-END:|26-getter|0|26-preInit
            // write pre-init user code here
            cmdBusqueda = new Command("Busqueda", Command.SCREEN, 0);//GEN-LINE:|26-getter|1|26-postInit
            // write post-init user code here
        }//GEN-BEGIN:|26-getter|2|
        return cmdBusqueda;
    }
    //</editor-fold>//GEN-END:|26-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: imageItem ">//GEN-BEGIN:|22-getter|0|22-preInit
    /**
     * Returns an initiliazed instance of imageItem component.
     * @return the initialized component instance
     */
    public ImageItem getImageItem() {
        if (imageItem == null) {//GEN-END:|22-getter|0|22-preInit
            // write pre-init user code here
            imageItem = new ImageItem("", getImage(), ImageItem.LAYOUT_DEFAULT, "<Missing Image>", Item.PLAIN);//GEN-BEGIN:|22-getter|1|22-postInit
            imageItem.setPreferredSize(60, 80);//GEN-END:|22-getter|1|22-postInit
            // write post-init user code here
        }//GEN-BEGIN:|22-getter|2|
        return imageItem;
    }
    //</editor-fold>//GEN-END:|22-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formBusqueda ">//GEN-BEGIN:|28-getter|0|28-preInit
    /**
     * Returns an initiliazed instance of formBusqueda component.
     * @return the initialized component instance
     */
    public Form getFormBusqueda() {
        if (formBusqueda == null) {//GEN-END:|28-getter|0|28-preInit
            // write pre-init user code here
            formBusqueda = new Form("Busqueda", new Item[] { getTableItem() });//GEN-BEGIN:|28-getter|1|28-postInit
            formBusqueda.addCommand(getCmdBackBusqueda());
            formBusqueda.setCommandListener(this);//GEN-END:|28-getter|1|28-postInit
            // write post-init user code here
        }//GEN-BEGIN:|28-getter|2|
        return formBusqueda;
    }
    //</editor-fold>//GEN-END:|28-getter|2|



    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: tableItem ">//GEN-BEGIN:|30-getter|0|30-preInit
    /**
     * Returns an initiliazed instance of tableItem component.
     * @return the initialized component instance
     */
    public TableItem getTableItem() {
        if (tableItem == null) {//GEN-END:|30-getter|0|30-preInit
            // write pre-init user code here
            tableItem = new TableItem(getDisplay(), "Directorio");//GEN-BEGIN:|30-getter|1|30-postInit
            tableItem.setModel(getSimpleTableModel());//GEN-END:|30-getter|1|30-postInit
            // write post-init user code here
        }//GEN-BEGIN:|30-getter|2|
        return tableItem;
    }
    //</editor-fold>//GEN-END:|30-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: simpleTableModel ">//GEN-BEGIN:|31-getter|0|31-preInit
    /**
     * Returns an initiliazed instance of simpleTableModel component.
     * @return the initialized component instance
     */
    public SimpleTableModel getSimpleTableModel() {
        if (simpleTableModel == null) {//GEN-END:|31-getter|0|31-preInit
            // write pre-init user code here
            simpleTableModel = new SimpleTableModel(new java.lang.String[][] {//GEN-BEGIN:|31-getter|1|31-postInit
                new java.lang.String[] { "" },
                new java.lang.String[] { "" },
                new java.lang.String[] { "" },
                new java.lang.String[] { "" },
                new java.lang.String[] { "" },
                new java.lang.String[] { "" },
                new java.lang.String[] { "" },
                new java.lang.String[] { "" },
                new java.lang.String[] { "" },
                new java.lang.String[] { "" }}, new java.lang.String[] { "Documento" });//GEN-END:|31-getter|1|31-postInit
            // write post-init user code here
        }//GEN-BEGIN:|31-getter|2|
        return simpleTableModel;
    }
    //</editor-fold>//GEN-END:|31-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cmdBackBusqueda ">//GEN-BEGIN:|32-getter|0|32-preInit
    /**
     * Returns an initiliazed instance of cmdBackBusqueda component.
     * @return the initialized component instance
     */
    public Command getCmdBackBusqueda() {
        if (cmdBackBusqueda == null) {//GEN-END:|32-getter|0|32-preInit
            // write pre-init user code here
            cmdBackBusqueda = new Command("Back", Command.BACK, 0);//GEN-LINE:|32-getter|1|32-postInit
            // write post-init user code here
        }//GEN-BEGIN:|32-getter|2|
        return cmdBackBusqueda;
    }
    //</editor-fold>//GEN-END:|32-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cmdAgregar ">//GEN-BEGIN:|36-getter|0|36-preInit
    /**
     * Returns an initiliazed instance of cmdAgregar component.
     * @return the initialized component instance
     */
    public Command getCmdAgregar() {
        if (cmdAgregar == null) {//GEN-END:|36-getter|0|36-preInit
            // write pre-init user code here
            cmdAgregar = new Command("Agregar", Command.SCREEN, 0);//GEN-LINE:|36-getter|1|36-postInit
            // write post-init user code here
        }//GEN-BEGIN:|36-getter|2|
        return cmdAgregar;
    }
    //</editor-fold>//GEN-END:|36-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cmdBackAgregar ">//GEN-BEGIN:|39-getter|0|39-preInit
    /**
     * Returns an initiliazed instance of cmdBackAgregar component.
     * @return the initialized component instance
     */
    public Command getCmdBackAgregar() {
        if (cmdBackAgregar == null) {//GEN-END:|39-getter|0|39-preInit
            // write pre-init user code here
            cmdBackAgregar = new Command("Atras", Command.BACK, 0);//GEN-LINE:|39-getter|1|39-postInit
            // write post-init user code here
        }//GEN-BEGIN:|39-getter|2|
        return cmdBackAgregar;
    }
    //</editor-fold>//GEN-END:|39-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formAgregar ">//GEN-BEGIN:|34-getter|0|34-preInit
    /**
     * Returns an initiliazed instance of formAgregar component.
     * @return the initialized component instance
     */
    public Form getFormAgregar() {
        if (formAgregar == null) {//GEN-END:|34-getter|0|34-preInit
            // write pre-init user code here
            formAgregar = new Form("Archivo seleccionado", new Item[] { getLbNombreArchivo(), getLbTamanio() });//GEN-BEGIN:|34-getter|1|34-postInit
            formAgregar.addCommand(getCmdBackAgregar());
            formAgregar.addCommand(getCmdBuscarArchivo());
            formAgregar.addCommand(getCmdAgregarArchivo());
            formAgregar.setCommandListener(this);//GEN-END:|34-getter|1|34-postInit
            // write post-init user code here
        }//GEN-BEGIN:|34-getter|2|
        return formAgregar;
    }
    //</editor-fold>//GEN-END:|34-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: fileBrowser ">//GEN-BEGIN:|42-getter|0|42-preInit
    /**
     * Returns an initiliazed instance of fileBrowser component.
     * @return the initialized component instance
     */
    public FileBrowser getFileBrowser() {
        if (fileBrowser == null) {//GEN-END:|42-getter|0|42-preInit
            // write pre-init user code here
            fileBrowser = new FileBrowser(getDisplay());//GEN-BEGIN:|42-getter|1|42-postInit
            fileBrowser.setTitle("fileBrowser");
            fileBrowser.setCommandListener(this);
            fileBrowser.addCommand(FileBrowser.SELECT_FILE_COMMAND);
            fileBrowser.addCommand(getCmdCancelBrowser());//GEN-END:|42-getter|1|42-postInit
            // write post-init user code here
        }//GEN-BEGIN:|42-getter|2|
        return fileBrowser;
    }
    //</editor-fold>//GEN-END:|42-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cmdCancelBrowser ">//GEN-BEGIN:|47-getter|0|47-preInit
    /**
     * Returns an initiliazed instance of cmdCancelBrowser component.
     * @return the initialized component instance
     */
    public Command getCmdCancelBrowser() {
        if (cmdCancelBrowser == null) {//GEN-END:|47-getter|0|47-preInit
            // write pre-init user code here
            cmdCancelBrowser = new Command("Cancel", Command.CANCEL, 0);//GEN-LINE:|47-getter|1|47-postInit
            // write post-init user code here
        }//GEN-BEGIN:|47-getter|2|
        return cmdCancelBrowser;
    }
    //</editor-fold>//GEN-END:|47-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: lbNombreArchivo ">//GEN-BEGIN:|51-getter|0|51-preInit
    /**
     * Returns an initiliazed instance of lbNombreArchivo component.
     * @return the initialized component instance
     */
    public StringItem getLbNombreArchivo() {
        if (lbNombreArchivo == null) {//GEN-END:|51-getter|0|51-preInit
            // write pre-init user code here
            lbNombreArchivo = new StringItem("Nombre Archivo", "");//GEN-BEGIN:|51-getter|1|51-postInit
            lbNombreArchivo.setFont(getFont1());//GEN-END:|51-getter|1|51-postInit
            // write post-init user code here
        }//GEN-BEGIN:|51-getter|2|
        return lbNombreArchivo;
    }
    //</editor-fold>//GEN-END:|51-getter|2|




    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: lbTamanio ">//GEN-BEGIN:|54-getter|0|54-preInit
    /**
     * Returns an initiliazed instance of lbTamanio component.
     * @return the initialized component instance
     */
    public StringItem getLbTamanio() {
        if (lbTamanio == null) {//GEN-END:|54-getter|0|54-preInit
            // write pre-init user code here
            lbTamanio = new StringItem("Tamanio", "", Item.PLAIN);//GEN-BEGIN:|54-getter|1|54-postInit
            lbTamanio.setFont(getFont1());//GEN-END:|54-getter|1|54-postInit
            // write post-init user code here
        }//GEN-BEGIN:|54-getter|2|
        return lbTamanio;
    }
    //</editor-fold>//GEN-END:|54-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: font1 ">//GEN-BEGIN:|56-getter|0|56-preInit
    /**
     * Returns an initiliazed instance of font1 component.
     * @return the initialized component instance
     */
    public Font getFont1() {
        if (font1 == null) {//GEN-END:|56-getter|0|56-preInit
            // write pre-init user code here
            font1 = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM);//GEN-LINE:|56-getter|1|56-postInit
            // write post-init user code here
        }//GEN-BEGIN:|56-getter|2|
        return font1;
    }
    //</editor-fold>//GEN-END:|56-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image ">//GEN-BEGIN:|57-getter|0|57-preInit
    /**
     * Returns an initiliazed instance of image component.
     * @return the initialized component instance
     */
    public Image getImage() {
        if (image == null) {//GEN-END:|57-getter|0|57-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|57-getter|1|57-@java.io.IOException
                image = Image.createImage("/tux-treo.jpg");
            } catch (java.io.IOException e) {//GEN-END:|57-getter|1|57-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|57-getter|2|57-postInit
            // write post-init user code here
        }//GEN-BEGIN:|57-getter|3|
        return image;
    }
    //</editor-fold>//GEN-END:|57-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: cmdAgregarArchivo ">//GEN-BEGIN:|58-getter|0|58-preInit
    /**
     * Returns an initiliazed instance of cmdAgregarArchivo component.
     * @return the initialized component instance
     */
    public Command getCmdAgregarArchivo() {
        if (cmdAgregarArchivo == null) {//GEN-END:|58-getter|0|58-preInit
            // write pre-init user code here
            cmdAgregarArchivo = new Command("Agregar Archivo", Command.SCREEN, 0);//GEN-LINE:|58-getter|1|58-postInit
            // write post-init user code here
        }//GEN-BEGIN:|58-getter|2|
        return cmdAgregarArchivo;
    }
    //</editor-fold>//GEN-END:|58-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: alertArchivoAgregado ">//GEN-BEGIN:|61-getter|0|61-preInit
    /**
     * Returns an initiliazed instance of alertArchivoAgregado component.
     * @return the initialized component instance
     */
    public Alert getAlertArchivoAgregado() {
        if (alertArchivoAgregado == null) {//GEN-END:|61-getter|0|61-preInit
            // write pre-init user code here
            alertArchivoAgregado = new Alert("Operacion exitosa", "Archivo agregado satisfactoriamente", null, AlertType.INFO);//GEN-BEGIN:|61-getter|1|61-postInit
            alertArchivoAgregado.setTimeout(10);//GEN-END:|61-getter|1|61-postInit
            // write post-init user code here
        }//GEN-BEGIN:|61-getter|2|
        return alertArchivoAgregado;
    }
    //</editor-fold>//GEN-END:|61-getter|2|

    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }
    
    public void updateResults(String[][] results){
       
        getSimpleTableModel().setValues(results);
        SimpleTableModel tm = new SimpleTableModel();
        tm.setValues(results);
        simpleTableModel = tm;
        tableItem.setModel(getSimpleTableModel());
    }
    
    
}
